﻿using System;
using System.Collections;

namespace Gencode.Controls.Harmonica
{
	public class HarmonicaEnumerator : IEnumerator
	{
		int index = 0;
		HarmonicaNodeCollection collection;

		public HarmonicaEnumerator(HarmonicaNodeCollection collection)
		{
			this.collection = collection;
		}

		#region IEnumerator Members

		public object Current
		{
			get
			{
				if (index >= collection.Count)
					index = collection.Count - 1;
				return collection[index];
			}
		}

		public bool MoveNext()
		{
			index++;
			if (index < collection.Count)
				return true;
			else
			{
				index--;
				return false;
			}
		}

		public void Reset()
		{
			index = 0;
		}

		#endregion
	}
}
